import { parseTime } from '@/utils'
export default {
  data() {
    return {
      coreDate: parseTime(new Date(), '{y}-{m}-{d}'),
      calendarMinDate: new Date(new Date().setMonth(new Date().getMonth() - 12)),
      calendarMaxDate: new Date(),
      showCalendar: false // 是否显示日历
    }
  },
  created() {
    const nowDate = new Date()
    const hour = nowDate.getHours()
    if (hour < 8) {
      // 当前时间小于8点，则日期取前一天的
      const day = nowDate.getDate() - 1
      nowDate.setDate(day)
      this.coreDate = parseTime(new Date(nowDate), '{y}-{m}-{d}')
      this.calendarMaxDate = nowDate
    }
  },
  computed: {
    coreDateShow() {
      return parseTime(this.coreDate, '{y}.{m}.{d}')
    }
  },
  methods: {
    onConfirmCalendar(date) {
      this.showCalendar = false
      this.coreDate = parseTime(date, '{y}-{m}-{d}')
    }
  }
}
